package com.gardenguell.salad.util;

import android.content.Context;
import android.content.SharedPreferences;
import com.gardenguell.salad.app.AppContext;

/**
 * Created by absurd on 2015/11/29.
 */
public class SharedPreferenceUtil {

    private static final String SETTING_INFOS = "salad";

    private static SharedPreferenceUtil mSharedPreferenceUtil;

    private SharedPreferences mSharedPreferences;
    private SharedPreferences.Editor mEditor;

    private SharedPreferenceUtil(Context context, String file) {
        // TODO Auto-generated constructor stub
        mSharedPreferences = context.getSharedPreferences(file, Context.MODE_PRIVATE);
        mEditor = mSharedPreferences.edit();
    }

    public synchronized static SharedPreferenceUtil getInstance(){
        if(mSharedPreferenceUtil == null){
            mSharedPreferenceUtil = new SharedPreferenceUtil(AppContext.getContext(), SETTING_INFOS);
        }
        return mSharedPreferenceUtil;
    }

    public String get(String key){
        return mSharedPreferences.getString(key,"");
    }


    public String get(String key, String de){
        return mSharedPreferences.getString(key, de);
    }

    public boolean get(String key, boolean de){
        return mSharedPreferences.getBoolean(key, de);
    }

    public void put(String key, String value){
        mEditor.putString(key, value)
                .commit();
    }

    public void put(String key, boolean value){
        mEditor.putBoolean(key, value)
                .commit();
    }

    public void clearAll(){
        mEditor.clear()
                .commit();
    }
}
